/*
 * @Author: 檃
 * @Date: 2022-06-20 11:03:56
 * @LastEditTime: 2022-06-20 13:32:04
 * @Description:
 * @LastEditors: 檃
 */
import react from '@vitejs/plugin-react'
import { resolve } from 'path'
import { defineConfig } from 'vite'
import { nodePolyfills } from 'vite-plugin-node-polyfills'

export default defineConfig({
  plugins: [
    nodePolyfills({
      // Whether to polyfill `node:` protocol imports.
      protocolImports: true
    }),
    react({
      babel: {
        plugins: [
          // '@babel/plugin-transform-runtime',
          // '@babel/plugin-proposal-object-rest-spread',
          // '@babel/plugin-syntax-dynamic-import',
          // ['@babel/plugin-proposal-decorators', { legacy: true }],
          // '@babel/plugin-proposal-class-properties',
          // '@babel/plugin-proposal-optional-chaining',
          // '@babel/plugin-proposal-nullish-coalescing-operator'
        ]
      }
    })
  ],
  base: './',
  server: {
    // 接口代理地址设置
    proxy: {
      '/api': 'http://192.168.66.210:9001/',
      '/ihs-gateway': {
        target: 'http://192.168.66.210:9001/',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/ihs-gateway/, '')
      }
    },
    // host: '192.168.3.58',
    open: true,
    strictPort: false
    // origin: 'http://dev.uchat.com.cn'
  },
  css: {
    preprocessorOptions: {
      less: {
        // 支持内联 JavaScript
        javascriptEnabled: true,
        module: true,
        // 重写 less 变量，定制样式
        modifyVars: {
          // '@primary-color': 'red' // TODO ! BUG 为什么要改这个颜色？
        }
      }
    }
  },
  resolve: {
    alias: [
      { find: '@', replacement: resolve('./', 'src') },
      { find: /^~antd/, replacement: resolve('./', 'node_modules/antd/') }
    ]
  },
  define: {
    'process.env': {}
  }
})
